
function formSubmit(obj){
	layer.load(1,{offset: '350px'});
	var content=$(obj);
	content.parents("form").submit();
}

function initPage(dataInfo){
	var basePath = $("#basePath").val();
	$("select:not([data-address])").each(function(){
		$(this).append("<option value=''>---请选择---</option>");
		
	});
	
	$("select[data-type='129Select']").each(function(){
		var options = "";
		options+="<option value='1'>是</option>";
		options+="<option value='2'>否</option>";
		options+="<option value='9'>-</option>";
		$(this).append(options);
	});
	
	$("select[data-type='proeesureSoresTime']").each(function(){
		var options = "";
		options+="<option value='1'>入院前</option>";
		options+="<option value='2'>住院期间</option>";
		options+="<option value='9'>-</option>";
		$(this).append(options);
	});
	
	$("select[data-type='alreadyProeesureSoresSource']").each(function(){
		var options = "";
		options+="<option value='1'>家庭</option>";
		options+="<option value='2'>养老院</option>";
		options+="<option value='3'>其他医院</option>";
		options+="<option value='4'>其他地方</option>";
		options+="<option value='9'>-</option>";
		$(this).append(options);
	});
	$("select[data-type='proeesureSoresNumber']").each(function(){
		var options = "";
		options+="<option value='1'>1处</option>";
		options+="<option value='2'>多处</option>";
		options+="<option value='9'>-</option>";
		$(this).append(options);
	});
	$("select[data-type='proeesureSoresPart']").each(function(){
		var options = "";
		options+="<option value='1'>骶尾椎骨处</option>";
		options+="<option value='2'>坐骨处</option>";
		options+="<option value='3'>股骨粗隆处</option>";
		options+="<option value='4'>跟骨处</option>";
		options+="<option value='5'>足踝处</option>";
		options+="<option value='6'>肩胛骨处</option>";
		options+="<option value='7'>枕骨处</option>";
		options+="<option value='8'>其他部位</option>";
		options+="<option value='9'>多处</option>";
		options+="<option value='19'>-</option>";
		$(this).append(options);
	});
	
	$("select[data-type='damageClassification']").each(function(){
		var options = "";
		options+="<option value='1'>1级</option>";
		options+="<option value='2'>2级</option>";
		options+="<option value='3'>3级</option>";
		options+="<option value='9'>-</option>";
		$(this).append(options);
	});
	
	$("select[data-type='fallDownCause']").each(function(){
		var options = "";
		options+="<option value='1'>健康原因</option>";
		options+="<option value='2'>治疗、药物、麻醉原因</option>";
		options+="<option value='3'>环境因素</option>";
		options+="<option value='4'>其他原因</option>";
		options+="<option value='9'>-</option>";
		$(this).append(options);
	});
	
	$("select[data-type='physicalConstraintWay']").each(function(){
		var options = "";
		options+="<option value='1'>1处</option>";
		options+="<option value='2'>2处</option>";
		options+="<option value='3'>3处</option>";
		options+="<option value='4'>其他</option>";
		options+="<option value='9'>-</option>";
		$(this).append(options);
	});
	
	$("select[data-type='physicalConstraintTool']").each(function(){
		var options = "";
		options+="<option value='1'>软式管</option>";
		options+="<option value='2'>硬式管</option>";
		options+="<option value='3'>背心</option>";
		options+="<option value='4'>老人椅</option>";
		options+="<option value='5'>约束带</option>";
		options+="<option value='6'>其他</option>";
		options+="<option value='9'>-</option>";
		$(this).append(options);
	});
	
	$("select[data-type='physicalConstraintCause']").each(function(){
		var options = "";
		options+="<option value='1'>认知障碍</option>";
		options+="<option value='2'>可能跌倒</option>";
		options+="<option value='3'>行为紊乱</option>";
		options+="<option value='4'>治疗需要</option>";
		options+="<option value='5'>躁动</option>";
		options+="<option value='6'>医疗限制</option>";
		options+="<option value='7'>其他原因</option>";
		options+="<option value='9'>-</option>";
		$(this).append(options);
	});
	
	$("select[data-type='obstetricTireTime']").each(function(){
		var options = "";
		options+="<option value='1'>1胎</option>";
		options+="<option value='2'>2胎</option>";
		options+="<option value='3'>3胎</option>";
		options+="<option value='4'>4胎</option>";
		options+="<option value='5'>5胎</option>";
		options+="<option value='6'>6胎</option>";
		options+="<option value='7'>7胎</option>";
		options+="<option value='9'>-</option>";
		$(this).append(options);
	});
	
	$("select[data-type='numberOfFetal']").each(function(){
		var options = "";
		options+="<option value='1'>1个</option>";
		options+="<option value='2'>2个</option>";
		options+="<option value='3'>3个</option>";
		options+="<option value='4'>4个</option>";
		options+="<option value='5'>5个</option>";
		options+="<option value='6'>6个</option>";
		options+="<option value='7'>7个</option>";
		options+="<option value='9'>-</option>";
		$(this).append(options);
	});
	
	$("select[data-type='degreeOfPerinealLaceration']").each(function(){
		var options = "";
		options+="<option value='1'>Ⅰ度</option>";
		options+="<option value='2'>Ⅱ度</option>";
		options+="<option value='3'>Ⅲ度</option>";
		options+="<option value='4'>无</option>";
		options+="<option value='9'>-</option>";
		$(this).append(options);
	});
	
	$("select[data-type='neonatalDischarge']").each(function(){
		var options = "";
		options+="<option value='1'>医嘱离院</option>";
		options+="<option value='2'>医嘱转院</option>";
		options+="<option value='3'>医嘱转社区卫生服务机构</option>";
		options+="<option value='4'>非医嘱离院</option>";
		options+="<option value='5'>死亡</option>";
		options+="<option value='6'>转新生儿监护室</option>";
		options+="<option value='9'>-</option>";
		$(this).append(options);
	});
	
	$("select").each(function(){
		$(this).change(function(){
	   		var eventObj = $(this);
	   		var nameObjName = eventObj.attr("name").replace("Code", "Name");
	   		
	   		if(eventObj.val()!=""){
	   			var name=eventObj.find("option:selected").text();
	   			eventObj.next("input[name='"+nameObjName+"']").val(name);
	   		}else{
	   			eventObj.next("input[name='"+nameObjName+"']").val("");
	   		}
	   });
	});
	
	$("input[type='radio']").each(function(){
		$(this).click(function(){
			 $(this).nextAll("input[name='"+$(this).attr("name").replace("Code", "Name")+"']").val($(this).attr("title"));
		});
		$(this).dblclick(function(){
			$(this).removeAttr("checked");
			$(this).nextAll("input[name='"+$(this).attr("name").replace("Code", "Name")+"']").val(null);
		});
	});
	initProeesureSores(dataInfo);
	initFallDown(dataInfo);
	initPhysicalConstraint(dataInfo);
	initObstetricDelivery(dataInfo);
	var validator = $("#nurseQualityControlInfoForm").validate({
		errorElement: "title",
		ignoreTitle: true,
		submitHandler : function(){
			return true;
		},
		rules:{
			'physicalConstraintInfo.physicalConstraintDay': {
				digits:true,
            	range:[1,1000]
            }
			
		},
		
	});
}
function initProeesureSores(dataInfo){
	var proeesureSoresInfo = dataInfo.proeesureSoresInfo;
	if(proeesureSoresInfo){
		selectValue("proeesureSoresInfo.whetherProeesureSoresCode",proeesureSoresInfo.whetherProeesureSoresCode,
				"proeesureSoresInfo.whetherProeesureSoresName",proeesureSoresInfo.whetherProeesureSoresName);
		
		selectValue("proeesureSoresInfo.proeesureSoresTimeCode",proeesureSoresInfo.proeesureSoresTimeCode,
				"proeesureSoresInfo.proeesureSoresTimeName",proeesureSoresInfo.proeesureSoresTimeName);
		
		selectValue("proeesureSoresInfo.alreadyProeesureSoresSourceCode",proeesureSoresInfo.alreadyProeesureSoresSourceCode,
				"proeesureSoresInfo.alreadyProeesureSoresSourceName",proeesureSoresInfo.alreadyProeesureSoresSourceName);
		
		selectValue("proeesureSoresInfo.proeesureSoresNumberCode",proeesureSoresInfo.proeesureSoresNumberCode,
				"proeesureSoresInfo.proeesureSoresNumberName",proeesureSoresInfo.proeesureSoresNumberName);
		
		selectValue("proeesureSoresInfo.proeesureSoresPartCode",proeesureSoresInfo.proeesureSoresPartCode,
				"proeesureSoresInfo.proeesureSoresPartName",proeesureSoresInfo.proeesureSoresPartName);
		
		
	}
}

function initFallDown(dataInfo){
	var fallDownInfo = dataInfo.fallDownInfo;
	if(fallDownInfo){
		radioValue("fallDownInfo.whetherFallDownCode",fallDownInfo.whetherFallDownCode,
				"fallDownInfo.whetherFallDownName",fallDownInfo.whetherFallDownName);
		
		/*selectValue("fallDownInfo.damageClassificationCode",fallDownInfo.damageClassificationCode,
				"fallDownInfo.damageClassificationName",fallDownInfo.damageClassificationName);*/
		$("input[name='fallDownInfo.damageClassificationName']").val(fallDownInfo.damageClassificationName);
		selectValue("fallDownInfo.fallDownCauseCode",fallDownInfo.fallDownCauseCode,
				"fallDownInfo.fallDownCauseName",fallDownInfo.fallDownCauseName);
		
		selectValue("fallDownInfo.whetheraAgainFallDownCode",fallDownInfo.whetheraAgainFallDownCode,
				"fallDownInfo.whetheraAgainFallDownName",fallDownInfo.whetheraAgainFallDownName);
	}
}

function initPhysicalConstraint(dataInfo){
	var physicalConstraintInfo = dataInfo.physicalConstraintInfo;
	if(physicalConstraintInfo){
		radioValue("physicalConstraintInfo.whetherPhysicalConstraintCode",physicalConstraintInfo.whetherPhysicalConstraintCode,
				"physicalConstraintInfo.whetherPhysicalConstraintName",physicalConstraintInfo.whetherPhysicalConstraintName);
		$("input[name='physicalConstraintInfo.physicalConstraintDay']").val(physicalConstraintInfo.physicalConstraintDay);
		selectValue("physicalConstraintInfo.physicalConstraintWayCode",physicalConstraintInfo.physicalConstraintWayCode,
				"physicalConstraintInfo.physicalConstraintWayName",physicalConstraintInfo.physicalConstraintWayName);
		
		selectValue("physicalConstraintInfo.physicalConstraintToolCode",physicalConstraintInfo.physicalConstraintToolCode,
				"physicalConstraintInfo.physicalConstraintToolName",physicalConstraintInfo.physicalConstraintToolName);
		
		selectValue("physicalConstraintInfo.physicalConstraintCauseCode",physicalConstraintInfo.physicalConstraintCauseCode,
				"physicalConstraintInfo.physicalConstraintCauseName",physicalConstraintInfo.physicalConstraintCauseName);
	}
}

function initObstetricDelivery(dataInfo){
	var obstetricDeliveryInfo = dataInfo.obstetricDeliveryInfo;
	if(obstetricDeliveryInfo){
		
		selectValue("obstetricDeliveryInfo.obstetricTireTimeCode",obstetricDeliveryInfo.obstetricTireTimeCode,
				"obstetricDeliveryInfo.obstetricTireTimeName",obstetricDeliveryInfo.obstetricTireTimeName);
		
		selectValue("obstetricDeliveryInfo.numberOfFetalCode",obstetricDeliveryInfo.numberOfFetalCode,
				"obstetricDeliveryInfo.numberOfFetalName",obstetricDeliveryInfo.numberOfFetalName);
		
		selectValue("obstetricDeliveryInfo.degreeOfPerinealLacerationCode",obstetricDeliveryInfo.degreeOfPerinealLacerationCode,
				"obstetricDeliveryInfo.degreeOfPerinealLacerationName",obstetricDeliveryInfo.degreeOfPerinealLacerationName);
		
		selectValue("obstetricDeliveryInfo.whetherBirthInjuryCode",obstetricDeliveryInfo.whetherBirthInjuryCode,
				"obstetricDeliveryInfo.whetherBirthInjuryName",obstetricDeliveryInfo.whetherBirthInjuryName);
		
		selectValue("obstetricDeliveryInfo.whetherInstrumentalDeliveryCode",obstetricDeliveryInfo.whetherInstrumentalDeliveryCode,
				"obstetricDeliveryInfo.whetherInstrumentalDeliveryName",obstetricDeliveryInfo.whetherInstrumentalDeliveryName);
		
		selectValue("obstetricDeliveryInfo.whetherNonAssistedDeliveryCode",obstetricDeliveryInfo.whetherNonAssistedDeliveryCode,
				"obstetricDeliveryInfo.whetherNonAssistedDeliveryName",obstetricDeliveryInfo.whetherNonAssistedDeliveryName);
		
		selectValue("obstetricDeliveryInfo.whetherInTheProductionCode",obstetricDeliveryInfo.whetherInTheProductionCode,
				"obstetricDeliveryInfo.whetherInTheProductionName",obstetricDeliveryInfo.whetherInTheProductionName);
		
		selectValue("obstetricDeliveryInfo.neonatalDischargeCode",obstetricDeliveryInfo.neonatalDischargeCode,
				"obstetricDeliveryInfo.neonatalDischargeName",obstetricDeliveryInfo.neonatalDischargeName);
	}
}
function selectValue(codeName,codeValue,nameName,nameValue){
	if(codeValue){
	  	var selectedIndex = $("select[name='"+codeName+"'] option[value='"+codeValue+"']").first().index();
		if (selectedIndex == -1) {
			var option = "<option selected value='" + codeValue + "'>" + nameValue + "</option>";
			$("select[name='"+codeName+"']").append(option);
		} else {
			$("select[name='"+codeName+"']").get(0).selectedIndex = selectedIndex;
		}
	}
	$("select[name='"+codeName+"']").next("input[name='"+nameName+"']").val(nameValue);
}

function radioValue(codeName,codeValue,nameName,nameValue){
	if(codeValue){
		$("input[name='"+codeName+"'][value='"+codeValue+"']").attr("checked",true);
	}
	$("input[name='"+nameName+"']").val(nameValue);
}